//
//  PushedCitys.m
//  SmartRoadShow
//
//  Created by Tracy E on 10-10-12.
//  Copyright 2010 simonwang142232@gmail.com. All rights reserved.
//

#import "PushedCitys.h"
#import "database.h"

@implementation PushedCitys
@synthesize _id,_city,_time,_title;


+ (int)insertPushedCityWithId:(NSString*)newsId City:(NSString *)city Time:(NSString *)Time Title:(NSString *)title {
	PLSqliteDatabase *db = [database setup];
	
	BOOL rs = [db executeUpdate:@"insert into PushedCitys (id,city,time,title) values(?,?,?,?)",[NSNumber numberWithInt:[newsId intValue]],city,Time,title];
	
    return rs;
}

- (id)initWithID:(NSInteger) ID City:(NSString *)City Time:(NSString *)Time Title:(NSString *)title{
	if (self = [super init]) {
		_id = ID;
		_city = [City retain];
		_time = [Time retain];
		_title = [title retain];
	}
	return self;
}

+(BOOL)findById:(NSString*)newsId{
	PLSqliteDatabase *db = [database setup];
	id<PLResultSet> rs;
	int count = 0;
	NSString *sql = [NSString stringWithFormat:@"select * from PushedCitys where id=%d",[newsId intValue]];
	
	rs = [db executeQuery:sql];
	while ([rs next])
	{
		count++;
	}
	if (count != 0) {
		return YES;
	}
	return NO;
}

//+ (BOOL)find:(NSString *)City Time:(NSString *)Time{
//	PLSqliteDatabase *db = [database setup];
//	id<PLResultSet> rs;
//	int count = 0;
//	NSString *sql = [NSString stringWithFormat:@"select * from PushedCitys where city like '%@' and time like '%@'",City,Time];
//	
//	rs = [db executeQuery:sql];
//	while ([rs next])
//	{
//		count++;
//	}
//	if (count != 0) {
//		return YES;
//	}
//	return NO;
//}

+(int)deleteById:(NSString*)newsId{
	PLSqliteDatabase *db = [database setup];
	NSString *sql = [NSString stringWithFormat:@"delete from PushedCitys where id=%d",[newsId intValue]];
	BOOL re = [db executeUpdate:sql];	
	return re;
}

//+ (int)deleteWhileCity:(NSString *)City Time:(NSString *)Time{
//	PLSqliteDatabase *db = [database setup];
//	NSString *sql = [NSString stringWithFormat:@"delete from PushedCitys where city like '%@' and time like '%@'",City,Time];
//	BOOL re = [db executeUpdate:sql];	
//	return re;
//}

@end
